package com.siruier.boss.ui.adapter

import android.graphics.Paint
import android.view.View
import com.siruier.boss.bean.MallGoodsBean
import com.siruier.boss.common.formatPriceRmb
import com.siruier.boss.databinding.ItemHomeGoodsBinding
import com.siruier.boss.ui.activity.mall.MallGoodsActivity
import com.siruier.boss.ui.base.BaseRecyclerAdapter
import com.siruier.boss.ui.ext.startActivityExt
import com.siruier.boss.ui.utils.GlideUtils
import jp.wasabeef.glide.transformations.RoundedCornersTransformation

class GoodsAdapter : BaseRecyclerAdapter<ItemHomeGoodsBinding, MallGoodsBean>() {
    override fun onBindViewHolder(vb: ItemHomeGoodsBinding, bean: MallGoodsBean, position: Int) {
        GlideUtils.intoRoundedCorners(
            vb.ivGoods.context, bean.picUrl, vb.ivGoods, roundingRadius = 6,
            cornerType = RoundedCornersTransformation.CornerType.TOP
        )
        vb.tvGoodsDesc.text = bean.name
        vb.tvGoodsMoney.text = bean.priceDesc
        vb.tvMarketPrice.text = bean.marketPrice.formatPriceRmb()
        vb.tvMarketPrice.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
        setViewClick(position, vb.root)
    }

    override fun subOnClickAdapter(v: View, position: Int) {
        v.context.startActivityExt<MallGoodsActivity> {
            putExtra("mGoodsId", getItem(position).id)
        }
    }
}